package com.sh.queue.practive;

/**
 * @ClassName ArrayQueue
 * @Description TODO
 * @Author yaoqiang
 * @Date 2020/10/26 15:00
 * @Version 1.0
 */
public class ArrayQueueNewDemo {
    public static void main(String[] args) {
        ArrayQueueNew arr=new ArrayQueueNew(3);
        //addQueue();getQueue();showQueue();showHead();
        arr.addQueue(10);  arr.addQueue(20);  arr.addQueue(30);
        arr.showQueue();
        arr.getQueue();  arr.getQueue();  arr.showQueue();
       arr.showHead();
    }
}

class ArrayQueueNew {
    public void showHead() { System.out.println(arr[front+1]); }
    public void addQueue(int n) { if (!isFull()) { rear++;arr[rear] = n; } }

    public void showQueue(){ for (int i=0;i<maxSize;i++) {
        System.out.println(arr[i]);
    }
    }

    public void getQueue(){ front++;System.out.println(arr[front]); }

    private int maxSize,front,rear;private int[] arr;

    public ArrayQueueNew(int arrMaxSize) { maxSize = arrMaxSize;arr = new int[arrMaxSize];front = -1;rear = -1; }

    public boolean isEmpty() { return front == rear; }

    public boolean isFull() { return maxSize - 1 == rear; }
}
